Skip to content

Conversation

adriendupuis
Copy link
Contributor

@adriendupuis adriendupuis commented Aug 8, 2025

🎫 Issue IBX-XXXXX

Description:

Sort parameter list when sortable, when it's an array of arrays by a scalar value's key.

For example, see admin siteaccess field templates by decreasing priority:
php bin/console ibexa:debug:config field_templates --siteaccess admin --sort priority --reverse-sort

For QA:

Documentation:

@adriendupuis adriendupuis force-pushed the enh-ibexa-debug-config branch 2 times, most recently from ea930f3 to 1aad6d2 Compare August 12, 2025 08:02
Copy link

@adriendupuis adriendupuis marked this pull request as draft August 20, 2025 11:53
@adriendupuis adriendupuis changed the title Added sorting options to ìbexa:debug:config` Added sorting options to ibexa:debug:config Aug 28, 2025
@adriendupuis adriendupuis force-pushed the enh-ibexa-debug-config branch from b484bd6 to 1050275 Compare October 14, 2025 10:01
@adriendupuis adriendupuis force-pushed the enh-ibexa-debug-config branch from a3c7fa8 to 7202bcd Compare October 14, 2025 15:07
@adriendupuis adriendupuis marked this pull request as ready for review October 14, 2025 16:04
@adriendupuis adriendupuis requested a review from adamwojs October 14, 2025 16:04
if (!array_is_list($parameterData)) {
throw new InvalidArgumentException('--sort', "'$parameter' is a hash but sort can be used only on a list (an array with numeral keys incremented from zero).");
}
for ($i = 0, $count = count($parameterData); $i < $count; ++$i) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for ($i = 0, $count = count($parameterData); $i < $count; ++$i) {
foreach ($parameterData as $i => $data) {

@adamwojs adamwojs requested a review from a team October 15, 2025 06:06
@ezrobot ezrobot requested review from Steveb-p, adamwojs, alongosz, ciastektk and mikadamczyk and removed request for a team October 15, 2025 06:06
throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item.");
}
if (!is_scalar($parameterData[$i][$sort])) {
throw new InvalidArgumentException('--sort', "'$sort' properties aren't always scalar and can't be sorted.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of letting these input-validation exceptions bubble, you could catch them, print a styled error, and return Command::INVALID or use Command::FAILURE for runtime errors.

if (!array_key_exists($sort, $parameterData[$i])) {
throw new InvalidArgumentException('--sort', "'$sort' property doesn't exist on each '$parameter' list item.");
}
if (!is_scalar($parameterData[$i][$sort])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is_scalar() allows bool, int, float, string. Mixed types across items (e.g., "10" and 2, or "abc" and 1) will be coerced by <=>, often in surprising ways (non-numeric strings become 0 in numeric comparisons). You could enforce type consistency across the list for the $sort key, or detect the predominant type and normalize.


if (null !== $sort && !empty($parameterData)) {
if (!is_array($parameterData)) {
throw new InvalidArgumentException('--sort', "'$parameter' isn't a list. Sort can be used only on a list.");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For CLI argument validation you could use a Symfony\Component\Console\Exception\InvalidArgumentException. It integrates better with Console error styling and exit codes.

Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants